$(document).ready(function(){
	$("#datepicker").datepicker({
		inline : true
	});
	/*-------------收入支出转账切换---------------*/
	$("#payout").click(function(){
		$(".select").removeAttr("class");
		$(this).addClass("select");
		
		$("#type-box-2").hide();
		$("#type-box-1").show();
		$("#tb-li-store").show();
		document.getElementById("tb-save").onclick = function(){payout();}
	});
	$("#income").click(function(){
		$(".select").removeAttr("class");
		$(this).addClass("select");
		$("#type-box-2").hide();
		$("#type-box-1").show();
		$("#tb-li-store").hide();
		document.getElementById("tb-save").onclick = function(){income();}
	});
	$("#transfers").click(function(){
		$(".select").removeAttr("class");
		$(this).addClass("select");
		
		$("#type-box-1").hide();
		$("#type-box-2").show();
	});
	/*------------显示和隐藏一级分类---------------*/
	$(".ls-input").blur(function(){
		$(".ls.ls1").css("visibility","hidden");
	});
	/*------------显示和隐藏二级分类并改变样式--------------*/
	$(".ls-li").mouseover(function(){
		$(this).children(".ls.ls2.ls2-hasChild").css("visibility","visible");
		$(this).addClass("mouseover");
	});
	$(".ls-li").mouseout(function(){
		$(this).children(".ls.ls2.ls2-hasChild").css("visibility","hidden");
		$(this).removeClass("mouseover");
	});
	/*--------------焦点样式改变事件---------------*/
	$("li").mouseover(function(){
		$(this).addClass("hover");
	});
	$("li").mouseout(function(){
		$(this).removeClass("hover");
	});
	/*--------------隐藏选项--------------*/
	$(".w_select").blur(function(){
		$(".w_select_box").css("visibility","hidden");
	});
	$('form').submit(function(){ 
		alert($(this).serialize()); 
		returnfalse; 
	});
});
/*--------------选择分类事件--------------*/
function levelSelect(payType,name,id){
	$(".ls-input").val(name);
	$("#tb-category").val(id);
	$(".ls.ls2.ls2-hasChild").css("visibility","hidden");
}
/*---------------选择事件--------------*/
function optionSelect(name,id,setName){
	$("#tb-"+setName+"_text").val(name);
	$("#tb-"+setName).val(id);
}
/*--------------显示选项--------------*/
function showOption(id){
	$("#"+id).css("visibility","visible");
}
/*--------------新增记账记录--------------*/
function income(){
	jQuery.ajax({ 
		ContentType: "application/json; charset=utf-8",
		dataType:"json",
	    type: "post", 
	    url: "/income",
	    data:$("#form1").serialize(),
	    success:function (data) {
	    	if(data == true){
				alert("添加成功");
			}else{
				alert("添加失败");
			}
	    }, 
	    error:function (XMLHttpRequest, textStatus, errorThrown) { 
			alert("记账出错:"+errorThrown);
	    }
	});
}
function payout(){
	var catetory = $.trim($("#tb-category").val());
	var account = $.trim($("#tb-account").val());
	var member = $.trim($("#tb-member").val());
	var createTime = $.trim($("#tb-createTime").val());
	var amount = $.trim($("#tb-amount").val());
	var project = $.trim($("#tb-project").val());
	var seller = $.trim($("#tb-seller").val());
	var summary = $.trim($("#tb-summary").val());
	jQuery.ajax({ 
		ContentType: "application/json; charset=utf-8",
		dataType:"json",
		type: "post", 
		url: "/payout", 
		data:{
			catetory:catetory,
			account:account,
			member:member,
			createTime:createTime,
			amount:amount,
			project:project,
			seller:seller,
			summary:summary,
		},
		success:function (data) {
			if(data == true){
				alert("添加成功");
			}else{
				alert("添加失败");
			}
		},
		error:function (XMLHttpRequest, textStatus, errorThrown) { 
			alert("记账出错:"+errorThrown);
		}
	});
}
function showError(str){
	
}